package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.HaArea;
import com.ruoyi.system.service.IHaAreaService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 地区数据Controller
 * 
 * @author 鲍小伟
 * @date 2025-11-04
 */
@RestController
@RequestMapping("/system/area")
public class HaAreaController extends BaseController
{
    @Autowired
    private IHaAreaService haAreaService;

    /**
     * 查询地区数据列表
     */
    @PreAuthorize("@ss.hasPermi('system:area:list')")
    @GetMapping("/list")
    public TableDataInfo list(HaArea haArea)
    {
        startPage();
        List<HaArea> list = haAreaService.selectHaAreaList(haArea);
        return getDataTable(list);
    }

    /**
     * 导出地区数据列表
     */
    @PreAuthorize("@ss.hasPermi('system:area:export')")
    @Log(title = "地区数据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HaArea haArea)
    {
        List<HaArea> list = haAreaService.selectHaAreaList(haArea);
        ExcelUtil<HaArea> util = new ExcelUtil<HaArea>(HaArea.class);
        util.exportExcel(response, list, "地区数据数据");
    }

    /**
     * 获取地区数据详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:area:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(haAreaService.selectHaAreaById(id));
    }

    /**
     * 新增地区数据
     */
    @PreAuthorize("@ss.hasPermi('system:area:add')")
    @Log(title = "地区数据", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HaArea haArea)
    {
        return toAjax(haAreaService.insertHaArea(haArea));
    }

    /**
     * 修改地区数据
     */
    @PreAuthorize("@ss.hasPermi('system:area:edit')")
    @Log(title = "地区数据", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HaArea haArea)
    {
        return toAjax(haAreaService.updateHaArea(haArea));
    }

    /**
     * 删除地区数据
     */
    @PreAuthorize("@ss.hasPermi('system:area:remove')")
    @Log(title = "地区数据", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(haAreaService.deleteHaAreaByIds(ids));
    }

    /**
     * 获取地区数据树形结构
     * 鲍小伟@20251105
     */
    @PreAuthorize("@ss.hasPermi('system:area:list')")
    @GetMapping("/tree")
    public AjaxResult getTree() {
        List<HaArea> tree = haAreaService.getAreaTree();
        return success(tree);
    }

}
